{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Check if Numbers Are Ascending in a Sentence"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: areNumbersAscending"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #检查句子中的数字是否递增"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>句子是由若干 <strong>token</strong> 组成的一个列表，<strong>token</strong> 间用 <strong>单个</strong> 空格分隔，句子没有前导或尾随空格。每个 token 要么是一个由数字 <code>0-9</code> 组成的不含前导零的 <strong>正整数</strong>&nbsp;，要么是一个由小写英文字母组成的 <strong>单词</strong> 。</p>\n",
    "\n",
    "<ul>\n",
    "\t<li>示例，<code>\"a puppy has 2 eyes 4 legs\"</code> 是一个由 7 个 token 组成的句子：<code>\"2\"</code> 和 <code>\"4\"</code> 是数字，其他像&nbsp;<code>\"puppy\"</code> 这样的 tokens 属于单词。</li>\n",
    "</ul>\n",
    "\n",
    "<p>给你一个表示句子的字符串 <code>s</code> ，你需要检查 <code>s</code> 中的 <strong>全部</strong> 数字是否从左到右严格递增（即，除了最后一个数字，<code>s</code> 中的 <strong>每个</strong> 数字都严格小于它 <strong>右侧</strong> 的数字）。</p>\n",
    "\n",
    "<p>如果满足题目要求，返回 <code>true</code>&nbsp;，否则，返回<em> </em><code>false</code> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<p><img alt=\"example-1\" src=\"https://assets.leetcode.com/uploads/2021/09/30/example1.png\" style=\"width: 637px; height: 48px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>句子中的数字是：1, 3, 4, 6, 12 。\n",
    "这些数字是按从左到右严格递增的 1 &lt; 3 &lt; 4 &lt; 6 &lt; 12 。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"hello world 5 x 5\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>句子中的数字是：<em><strong>5</strong></em>, <strong><em>5</em></strong> 。这些数字不是严格递增的。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<p><img alt=\"example-3\" src=\"https://assets.leetcode.com/uploads/2021/09/30/example3.png\" style=\"width: 794px; height: 48px;\" /></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>s 中的数字是：7, <em><strong>51</strong></em>, <em><strong>50</strong></em>, 60 。这些数字不是严格递增的。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 4：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"4 5 11 26\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>s 中的数字是：4, 5, 11, 26 。\n",
    "这些数字是按从左到右严格递增的：4 &lt; 5 &lt; 11 &lt; 26 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>3 &lt;= s.length &lt;= 200</code></li>\n",
    "\t<li><code>s</code> 由小写英文字母、空格和数字 <code>0</code> 到 <code>9</code> 组成（包含 <code>0</code> 和 <code>9</code>）</li>\n",
    "\t<li><code>s</code> 中数字 token 的数目在 <code>2</code> 和 <code>100</code> 之间（包含 <code>2</code> 和 <code>100</code>）</li>\n",
    "\t<li><code>s</code> 中的 token 之间由单个空格分隔</li>\n",
    "\t<li><code>s</code> 中至少有 <strong>两个</strong> 数字</li>\n",
    "\t<li><code>s</code> 中的每个数字都是一个 <strong>小于</strong> <code>100</code> 的 <strong>正</strong> 数，且不含前导零</li>\n",
    "\t<li><code>s</code> 不含前导或尾随空格</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [check-if-numbers-are-ascending-in-a-sentence](https://leetcode.cn/problems/check-if-numbers-are-ascending-in-a-sentence/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [check-if-numbers-are-ascending-in-a-sentence](https://leetcode.cn/problems/check-if-numbers-are-ascending-in-a-sentence/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"', '\"hello world 5 x 5\"', '\"sunset is at 7 51 pm overnight lows will be in the low 50 and 60 s\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        a=s.split()\n",
    "        pre=0\n",
    "        for i in a:\n",
    "            if i[0].isdigit():\n",
    "                if pre>=int(i):\n",
    "                    return False\n",
    "                pre=int(i)\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        a = [int(t) for t in s.split() if t.isdigit()]\n",
    "        return sorted(a) == a and len(set(a)) == len(a)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        l = s.split(\" \")\n",
    "        l2 = []\n",
    "        for i in l:\n",
    "            if i.isdigit():\n",
    "                if not l2:\n",
    "                    l2.append(int(i))\n",
    "                elif int(i) > l2[-1]:\n",
    "                    l2.append(int(i))\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        a=s.split()\n",
    "        pre=0\n",
    "        for i in a:\n",
    "            if i.isdigit():\n",
    "                if pre>=int(i):\n",
    "                    return False\n",
    "                pre=int(i)\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "      s_=[]\n",
    "      for i in range(len(s)-1):\n",
    "        if s[i].isdigit():\n",
    "          if s[i+1].isdigit(): \n",
    "            s_.append(10*int(s[i])+int(s[i+1]))\n",
    "          if not s[i-1].isdigit() and not s[i+1].isdigit():\n",
    "            s_.append(int(s[i]))\n",
    "      if(s[len(s)-1].isdigit() and  not s[len(s)-2].isdigit()):\n",
    "        s_.append(int(s[len(s)-1]))\n",
    "      for i in range(len(s_)-1):\n",
    "        if s_[i]>=s_[i+1]:\n",
    "          return False\n",
    "      return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        list_s = [int(i) for i in s.split(' ') if i.isdigit()]\n",
    "        for i in range(len(list_s)-1):\n",
    "            if list_s[i] >= list_s[i+1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        nums = [int(word) for word in s.split() if word.isdigit()]\n",
    "        for i in range(1, len(nums)):\n",
    "            if nums[i] <= nums[i-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        return all(a < b for a, b in itertools.pairwise(map(int.__call__, filter(str.isdigit, s.split()))))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        self.s = s\n",
    "        self.s1 = self.s.split(' ')\n",
    "        self.s2 = []\n",
    "\n",
    "        for i in self.s1:\n",
    "            if i.isdigit():\n",
    "                self.s2.append(int(i))\n",
    "\n",
    "        flag = True\n",
    "        for i in range(len(self.s2) - 1):\n",
    "            for j in range(len(self.s2) - 1 - i):\n",
    "                if self.s2[j] >= self.s2[j+1]:\n",
    "                    flag = False\n",
    "                    break\n",
    "        return flag\n",
    "\n",
    "fun = Solution()\n",
    "s = \"1 box has 3 blue 4 red 6 green and 12 yellow marbles\"\n",
    "result = fun.areNumbersAscending(s)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        a=0\n",
    "        s=s.split()\n",
    "        for i in s:\n",
    "            if i.isdigit():\n",
    "                if a>=int(i):\n",
    "                    return False\n",
    "                a=int(i)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = -1\n",
    "        for w in s.split(' '):\n",
    "            if w and all(ch.isdigit() for ch in w):\n",
    "                if int(w) <= pre:\n",
    "                    return False\n",
    "                pre = int(w)\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "\n",
    "        s=[int(i) for i in s.split() if i.isdigit()]\n",
    "        \n",
    "        for i in range(1,len(s)):\n",
    "            if s[i]<=s[i-1]:\n",
    "                return False\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0\n",
    "        for t in s.split():\n",
    "            if t[0].isdigit():\n",
    "                if (cur := int(t)) <= pre:\n",
    "                    return False\n",
    "                pre = cur\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        min=0\n",
    "        for a in s.split(' '):\n",
    "            if a.isdigit():\n",
    "                if int(a)<=min:\n",
    "                    return False\n",
    "                else:\n",
    "                    min=int(a)\n",
    "        return True                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pattern = r'\\d+'  # 匹配一个或多个数字\n",
    "        numbers = [int(x) for x in re.findall(pattern, s)]\n",
    "        \n",
    "        # 检查是否有重复数字\n",
    "        if len(numbers) != len(set(numbers)):\n",
    "            return False\n",
    "        \n",
    "        # 检查是否按升序排列\n",
    "        for i in range(1, len(numbers)):\n",
    "            if numbers[i] < numbers[i-1]:\n",
    "                return False\n",
    "        \n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        alpha_list = \"abcdefghijklmnopqrstuvwxyz\"\n",
    "        alpha_dic = {}\n",
    "        for i in range(26):\n",
    "            alpha_dic[alpha_list[i]] = \"\"\n",
    "\n",
    "        s_list = s.split()\n",
    "        s_num_list = [int(x) for x in s_list if x[0] not in alpha_dic]\n",
    "\n",
    "        for n in range(1,len(s_num_list)):\n",
    "            if s_num_list[n] <= s_num_list[n-1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        digit = [int(i) for i in s.split() if i.isdigit()]\n",
    "        d = sorted(digit)\n",
    "        if len(set(digit)) != len(digit):return False\n",
    "        return d == digit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        num = [chr(x) for x in range(ord('0'), ord('9') + 1)]\n",
    "        _list = s.split(' ')\n",
    "        ans = True\n",
    "        val = 0\n",
    "        for x in _list:\n",
    "            if x[0] in num:\n",
    "                if int(x) <= val:\n",
    "                    ans = False\n",
    "                    break\n",
    "                else:\n",
    "                    val = int(x)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        a = s.split(' ')\n",
    "        ans = []\n",
    "        for i in a:\n",
    "            if i[0] in '123456789':\n",
    "                ans.append(int(i))   \n",
    "        b = sorted(ans)\n",
    "        return ans == b and len(set(ans)) == len(ans)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        arr = s.split(' ')\n",
    "        tmp = 0\n",
    "        for x in arr:\n",
    "            if x.isdigit():\n",
    "                if tmp < int(x):\n",
    "                    tmp = int(x)\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        n = 0\n",
    "        for w in s.split():\n",
    "            if w.isdigit():\n",
    "                i = int(w)\n",
    "                if i <= n:\n",
    "                    return False\n",
    "                n = i\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        stack = 0\n",
    "        for x in s.split():\n",
    "            if x.isdigit():\n",
    "                temp = int(x)\n",
    "                if stack and stack >= temp:\n",
    "                    return False\n",
    "                else:\n",
    "                    stack = temp\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        p1, p2 = 0, 0\n",
    "        for i in s.split():\n",
    "            if i.isdigit():\n",
    "                p2, p1 = p1, p2\n",
    "                p2 = int(i)\n",
    "                if p2 <= p1: return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        s=s.split()\n",
    "        a=[]\n",
    "        for x in s:\n",
    "            if ord(x[0])>=ord('0') and ord(x[0])<=ord('9'):\n",
    "                a.append(int(x))\n",
    "        for i in range(len(a)-1):\n",
    "            if a[i]>=a[i+1]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        left, right = -2, -1\n",
    "        s += ' '\n",
    "        n = len(s)\n",
    "        token = s[0]\n",
    "        for i in range(1, n):\n",
    "            if s[i] == ' ':\n",
    "                if s[i-1].isdigit():\n",
    "                    left = right\n",
    "                    right = int(token)\n",
    "                    if right <= left:\n",
    "                        return False\n",
    "                token = ''\n",
    "            else:\n",
    "                token += s[i]\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        stack = 0\n",
    "        for x in s.split():\n",
    "            if x.isdigit():\n",
    "                temp = int(x)\n",
    "                if stack and stack >= temp:\n",
    "                    return False\n",
    "                else:\n",
    "                    stack = temp\n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        l=[]\n",
    "        for i in s.split():\n",
    "            if i.isnumeric():\n",
    "                l.append(int(i))\n",
    "        return l==sorted(list(set(l)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        num = [chr(x) for x in range(ord('0'), ord('9') + 1)]\n",
    "        _list = s.split(' ')\n",
    "        ans = True\n",
    "        val = 0\n",
    "        for x in _list:\n",
    "            if x[0] in num:\n",
    "                if int(x) <= val:\n",
    "                    ans = False\n",
    "                    break\n",
    "                else:\n",
    "                    val = int(x)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0\n",
    "        for t in s.split():\n",
    "            if t[0].isdigit():\n",
    "                if (cur := int(t)) <= pre:\n",
    "                    return False\n",
    "                pre = cur\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0\n",
    "        for t in s.split():\n",
    "            if t[0].isdigit():\n",
    "                if (cur := int(t)) <= pre:\n",
    "                    return False\n",
    "                pre = cur\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre=i=0\n",
    "        while i<len(s):\n",
    "            if s[i].isdigit():\n",
    "                cur=0\n",
    "                while i<len(s) and s[i].isdigit():\n",
    "                    cur=cur*10+int(s[i])\n",
    "                    i+=1\n",
    "                if cur<=pre:\n",
    "                    return False\n",
    "                pre=cur\n",
    "            else:\n",
    "                i+=1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        res = re.findall('(\\d+)',s)\n",
    "        if len(res)!=len(set(res)):\n",
    "            return False\n",
    "        res1 = sorted(res,key= lambda x:int(x))\n",
    "        return res==res1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = -100\n",
    "        for word in s.split():\n",
    "            if all(c.isdigit() for c in word):\n",
    "                x = int(word)\n",
    "                if x<=pre:\n",
    "                    return False\n",
    "                pre = x\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        ns = [int(x) for x in re.findall(r'\\d+',s)]\n",
    "        return all(ns[i] < ns[i+1] for i in range(len(ns)-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre=i=0\n",
    "        while i<len(s):\n",
    "            if s[i].isdigit():\n",
    "                cur=0\n",
    "                while i<len(s) and s[i].isdigit():\n",
    "                    cur=cur*10+int(s[i])\n",
    "                    i+=1\n",
    "                if cur<=pre:\n",
    "                    return False\n",
    "                pre=cur\n",
    "            else:\n",
    "                i+=1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        sl=s.split()\n",
    "        res=[]\n",
    "        for i in sl:\n",
    "            if i.isdigit():\n",
    "                res.append(i)\n",
    "        flag=True\n",
    "        for i in range(1,len(res)):\n",
    "            if int(res[i])-int(res[i-1])<=0:\n",
    "                flag=False\n",
    "        return flag"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        ns = [int(x) for x in re.findall(r'\\d+',s)]\n",
    "        return all(ns[i] < ns[i+1] for i in range(len(ns)-1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pattern = r'\\d+'  # 匹配一个或多个数字\n",
    "\n",
    "        numbers = [int(x) for x in re.findall(pattern, s)]\n",
    "        for i in numbers:\n",
    "            if numbers.count(i)>1:\n",
    "                return False\n",
    "        return numbers==sorted(numbers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        ls=s.split(\" \")\n",
    "        temp=0\n",
    "        for i in ls:\n",
    "            if i.isnumeric():\n",
    "                if int(i)>temp:\n",
    "                    temp=int(i)\n",
    "                else:\n",
    "                    return False\n",
    "            else:\n",
    "                continue\n",
    "        return True\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        ans = 0\n",
    "        for x in s.split():\n",
    "            if x[0].isdigit():\n",
    "                if (cur:= int(x)) <= ans:\n",
    "                    return False\n",
    "                ans = cur\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        arr = s.split(' ')\n",
    "        tmp = -inf\n",
    "        for i in arr:\n",
    "            if i.isdigit():\n",
    "                if int(i) > tmp:\n",
    "                    tmp = int(i)\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        num = [chr(x) for x in range(ord('0'), ord('9') + 1)]\n",
    "        _list = s.split(' ')\n",
    "        ans = True\n",
    "        val = 0\n",
    "        for x in _list:\n",
    "            if x[0] in num:\n",
    "                if int(x) <= val:\n",
    "                    ans = False\n",
    "                    break\n",
    "                else:\n",
    "                    val = int(x)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0;\n",
    "        for sss in s.split():\n",
    "            if sss[0].isdigit():\n",
    "                if (cur := int(sss)) <= pre:\n",
    "                    return False;\n",
    "                pre = cur;\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        stand = -1\n",
    "        x = 0\n",
    "        s += \" \"\n",
    "        while x < len(s):\n",
    "            if '0' <= s[x] <= '9':\n",
    "                y = x + 1\n",
    "                while y < len(s):\n",
    "                    if '0' <= s[y] <= '9':\n",
    "                        y += 1\n",
    "                    else:\n",
    "                        if int(s[x: y]) > stand:\n",
    "                            stand = int(s[x: y])\n",
    "                        else:\n",
    "                            return False\n",
    "                        x = y + 1\n",
    "                        break\n",
    "            else:\n",
    "                x += 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = i = 0\n",
    "        while i < len(s):\n",
    "            if s[i].isdigit():\n",
    "                cur = 0\n",
    "                while i < len(s) and s[i].isdigit():\n",
    "                    cur = cur * 10 + int(s[i])\n",
    "                    i += 1\n",
    "                if cur <= pre:\n",
    "                    return False\n",
    "                pre = cur\n",
    "            else:\n",
    "                i += 1\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        arr = [int(x) for x in s.split(\" \") if x.isdigit()]\n",
    "        return arr == sorted(arr) and len(set(arr)) == len(arr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0\n",
    "        for word in s.split(\" \"):\n",
    "            if word[0].isdigit():\n",
    "                if int(word) <= pre:\n",
    "                    return False\n",
    "                else:\n",
    "                    pre = int(word)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        nums = [int(ch) for ch in s.split(' ') if ch.isdigit()]\n",
    "        if len(set(nums)) != len(nums) :\n",
    "            return False\n",
    "        else:\n",
    "            if sorted(nums) == nums:\n",
    "                return True\n",
    "            else:\n",
    "                return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = 0\n",
    "        for t in s.split():\n",
    "            if t.isdigit():\n",
    "                if int(t) > pre:\n",
    "                    pre = int(t)\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = i = 0\n",
    "        while i < len(s):\n",
    "            if s[i].isdigit():\n",
    "                cur = 0\n",
    "                while i < len(s) and s[i].isdigit():\n",
    "                    cur = cur * 10 + int(s[i])\n",
    "                    i += 1\n",
    "                if cur <= pre:\n",
    "                    return False\n",
    "                pre = cur\n",
    "            else:\n",
    "                i += 1\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        left, right = -2, -1\n",
    "        s += ' '\n",
    "        n = len(s)\n",
    "        token = s[0]\n",
    "        for i in range(1, n):\n",
    "            if s[i] == ' ':\n",
    "                if s[i-1].isdigit():\n",
    "                    left = right\n",
    "                    right = int(token)\n",
    "                    if right <= left:\n",
    "                        return False\n",
    "                token = ''\n",
    "            elif s[i] != ' ':\n",
    "                token += s[i]\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        pre = -100\n",
    "        for word in s.split():\n",
    "            if all(ord('0')<=ord(c)<=ord('9') for c in word):\n",
    "                x = int(word)\n",
    "                if x<=pre:\n",
    "                    return False\n",
    "                pre = x\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        maxNum = 0\n",
    "        for b in s.split(\" \"):\n",
    "            if b.isdigit():\n",
    "                if maxNum < int(b):\n",
    "                    maxNum = int(b)\n",
    "                else:\n",
    "                    return False\n",
    "        return True\n",
    "                \n",
    "                "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        arr = s.split(' ')\n",
    "        tmp = 0\n",
    "        for i in arr:\n",
    "            if i.isdigit():\n",
    "                if int(i) <= tmp:\n",
    "                    return False\n",
    "                tmp = int(i)\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        sl = [int(i) for i in s.split(' ') if re.match('^[0-9]+$', i)]\n",
    "        return all(x < y for x, y in zip(sl, sl[1:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import re\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        sl = [int(i) for i in s.split(' ') if re.match('^[0-9]+$', i)]\n",
    "        return all(x < y for x,y in zip(sl, sl[1:]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        s = s + ' '\n",
    "        start = 0\n",
    "        last_num = 0\n",
    "        res = True\n",
    "        for i in range(len(s)):\n",
    "            if s[i] == ' ':\n",
    "                if s[start:i].isdigit() and int(s[start:i]) <= last_num:\n",
    "                    res = False\n",
    "                    break\n",
    "                elif s[start:i].isdigit() and int(s[start:i]) > last_num:\n",
    "                    last_num = int(s[start:i])\n",
    "                start = i+1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def areNumbersAscending(self, s: str) -> bool:\n",
    "        arr = s.split(' ')\n",
    "        tmp = -inf\n",
    "        for i in arr:\n",
    "            if i.isdigit():\n",
    "                if int(i) > tmp:\n",
    "                    tmp = int(i)\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
